package org.loofer.ext.utils;

import android.app.Activity;
import android.os.SystemClock;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import org.loofer.ext.component.cache.sp.Once;
import org.loofer.ext.component.logger.Logger;
import java.lang.ref.WeakReference;

public class GuideUtils {
    private static volatile boolean sIsShowing;
    private static volatile WeakReference<PopupWindow> sRefWindow;

    public static void showGuide(Activity context, int drawableResourceId) {
        try {
            if (sIsShowing) {
                LinearLayout content = new LinearLayout(context);
                PopupWindow window = new PopupWindow(context);
                window.setOutsideTouchable(true);
                window.setFocusable(true);
                window.setWidth(-1);
                window.setHeight(-1);
                window.setContentView(content);
                window.setBackgroundDrawable(context.getResources().getDrawable(drawableResourceId));
                window.showAtLocation(context.getWindow().getDecorView(), 17, 0, 0);
                window.setTouchInterceptor(GuideUtils$$Lambda$1.lambdaFactory$(window));
                window.setOnDismissListener(GuideUtils$$Lambda$4.lambdaFactory$());
                sRefWindow = new WeakReference(window);
            }
        } catch (Exception e) {
        }
    }

    private static /* synthetic */ void lambda$showGuide$4() {
        sIsShowing = false;
        sRefWindow.clear();
    }

    public static void showGuideOnce(Activity context, int drawableResourceId, String keyName) {
        new Thread(GuideUtils$$Lambda$5.lambdaFactory$(keyName, context, drawableResourceId)).start();
    }

    private static /* synthetic */ void lambda$showGuideOnce$5(final String str, final Activity activity, final int i) {
        try {
            if (!Once.beenDone(1, str)) {
                sIsShowing = true;
                SystemClock.sleep(500);
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        try {
                            GuideUtils.showGuide(activity, i);
                            Once.markDone(str);
                        } catch (Exception ex) {
                            Logger.e("showVeilPictureOnce " + str, ex.getMessage(), ex);
                        }
                    }
                });
            }
        } catch (Exception ex) {
            Logger.e("showVeilPictureOnce " + str, ex.getMessage(), ex);
        }
    }
}
